/*
 * ChooseDeliveryFragment.java
 * business
 *
 * Created by ChenTao on 2017/2/14.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.shoppingcart.choosedelivery;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ListView;

import com.yidiandao.business.R;
import com.yidiandao.business.base.BaseFragment;
import com.yidiandao.business.ui.adapter.ChooseShippingWayAdapter;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

/**
 * 选择配送方式 View
 *
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/14 9:39
 */
public class ChooseShoppingWayFragment extends BaseFragment implements
        ChooseShippingWayContract.View {

    private ChooseShippingWayContract.Presenter mPresenter;

    private Toolbar mToolbar;

    private ListView mListView;

    private ChooseShippingWayAdapter mAdapter;

    public static ChooseShoppingWayFragment getInstance(Bundle bundle) {
        ChooseShoppingWayFragment fragment = new ChooseShoppingWayFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void setPresenter(ChooseShippingWayContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return ChooseShoppingWayFragment.class.getSimpleName();
    }

    @Override
    public void showToast(String text) {
        UIUtils.showToast(text);
    }

    @Override
    protected void initViews() {
        mToolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
        mListView = (ListView) mRootView.findViewById(R.id.list_view);

        mPresenter.extraBundle(getArguments());
        initListView();
        initListeners();
    }

    private void initListView() {
        mAdapter = new ChooseShippingWayAdapter(mActivity);
        mListView.setAdapter(mAdapter);
    }

    private void initListeners() {
        mToolbar.setNavigationOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finishActivity();
                    }
                });
    }

    @Override
    public void setDisplayListItems(List<DisplayListItem> displayListItems) {
        mAdapter.setData(displayListItems);
    }

    @Override
    public void finishActivity() {
        mActivity.finish();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_choose_shipping_way;
    }
}
